package com.neuedu.funlifebbs.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neuedu.funlifebbs.bean.Labels;
import com.neuedu.funlifebbs.dao.LabelsMapper;
import com.neuedu.funlifebbs.query.LabelsQuery;
import com.neuedu.funlifebbs.service.LabelsService;

/**
 * 
 * @author myh
 * @version 2019年8月19日下午1:44:35
 *
 */
@Service
public class LabelsServiceImpl implements LabelsService {

	@Autowired
	LabelsMapper labelsMapper;

	@Override
	public Labels findById(int id) {
		return labelsMapper.findById(id);
	}

	@Override
	public List<Labels> findAll() {
		return labelsMapper.findAll();
	}

	@Override
	public PageInfo<Labels> query(LabelsQuery labelsQuery) {
		// 要不要分页
		if (labelsQuery.isPaging()) {
			// 使用分页插件
			PageHelper.startPage(labelsQuery.getPageNum(),
					labelsQuery.getLimit());
			Page<Labels> pageInfo = (Page<Labels>) labelsMapper
					.query(labelsQuery);
			return pageInfo.toPageInfo();
		} else {
			PageInfo<Labels> pageInfo = new PageInfo<Labels>(
					labelsMapper.query(labelsQuery));
			return pageInfo;
		}
	}

	@Override
	public int add(Labels labels) {
		return labelsMapper.add(labels);
	}

	@Override
	public int deleteById(int id) {
		return labelsMapper.deleteById(id);
	}

	@Override
	public int update(Labels labels) {
		return labelsMapper.update(labels);
	}

}
